<template>
  <h2>readonly 和 shallowReadonly</h2>
  <h3>state:{{ state }}</h3>
  <hr />
  <button @click="update">更新数据</button>
</template>
<script lang="ts">
import { defineComponent, reactive, readonly, shallowReadonly } from "vue";
export default defineComponent({
  name: "App",
  setup() {
    const state = reactive({
      name: "小明",
      age: 20,
      car: {
        name: "奔驰",
        car: "red",
      },
    });
    // 只读的数据 -- 深度只读
    // const state2 = readonly(state);
    // 只读的数据 -- 浅只读
    const state2 = shallowReadonly(state);
    const update = () => {
      // state2.name += '==='
      state2.car.name += '==='
    };
    return { state, update };
  },
});
</script>